<template>
  <div class="advanced-search-box">
      <Form
        :model="searchForm"
        ref="searchForm"
        :rules="ruleValidate"
        label-position="right"
        :label-width="120"
      >
        <Row :gutter="10" class="code-row-bg">
            <Col span="18">
              <Form-item :label="'更新版本:'" prop="exportType">
                <Select transfer v-model="searchForm.exportType" clearable>
                  <Option v-for="item in versionList" :value="item.key" :key="item.key">{{
                    item.value
                  }}</Option>
                </Select>
              </Form-item>
            </Col>
        </Row>
      </Form>

      <div class="foot-btn-box">
        <RPButton text="取消" @click="handleClose"/>
        <RPButton optType="create" type="info" text="确定" @click="handleSubmit"/>
      </div>
  </div>
  </template>
  
  <script>
  import {versionList } from '../dataConfig.js'
  import coverApi from '@/api/cover'
  export default {
    props: {
      fromPage: {
        type: String,
        default() {
          return "";
        }
      },
      idList:{
        type: Array,
        default() {[]}
      }
    },
    data() {
      return {
        versionList:[],
        searchForm:{
          idList:[],
          exportType:""
        },
        ruleValidate:{
          exportType: [
            { required: true, message: '请选择更新版本', trigger: 'change' }
          ]
        }
      }
    },
    created() {
       this.$emit("SetTitle", "导出表格");
       this.$emit("SetPageMinHeight", 100);
       this.$emit("SetPageWidth", 600);
       if(this.idList?.length){
        this.versionList = [...versionList];
        this.searchForm.idList = this.idList.map(ele => ele.id);
       }
       else{
        this.versionList = versionList.filter(ele => ele.key != 2);
        this.searchForm.idList = [];
       }
    },

    methods: {
      handleClose() {
        this.$emit("Close",false);
      },
  
      handleSubmit() {
        this.$refs["searchForm"].validate(valid => {
          if (valid) {
            this.taskExport()
          }
        })
      },

      getUrl(type, pathname) {
        return window.RPConfig[type] + pathname;
      },

      // 导出
      taskExport() {
        const url = window.origin + '/' +this.getUrl('itShare', `/wfGroupRptPlantask/export?exportType=${this.searchForm.exportType}`)
        coverApi.downloadFile2(url, this.searchForm.idList).then((result) => {
          if(result.data.code == 200){
            this.$Message.success({
              content: '导出成功',
              duration: 3
            })
          } else {
            this.$Message.error({
              content: result.data.msg || '导出失败',
              duration: 3
            })
          }
        })
      },
    }
  }
  </script>
  <style lang="less" scoped>
  .advanced-search-box {
    .foot-btn-box {
      text-align: right;
      button {
        margin-left: 10px;
      }
      .primary-button {
          color: #fff;
          background-color: #ff6f4b;
          border-color: #ff6f4b;
          font-size: 80;
      }
    }
    
    .Selecequarters{
      display:flex;
      
      /deep/.ivu-form-item-content{
            margin-left: 2px;
            width: 200px;
    
      }
    }
  }
  </style>
  
  